<template>
  <div>
    <el-row>
      <el-col :span="24">
        <el-form :inline="true" class="demo-form-inline">
          <el-form-item label="">
            <el-input
              v-model="foodName"
              size="medium"
              placeholder="查询用户名"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button size="small" type="success" icon="el-icon-search"
              >查询</el-button
            >
          </el-form-item>
          <el-form-item label="">
            <el-button size="small" type="warning" icon="el-icon-delete-solid"
              >清空</el-button
            >
          </el-form-item>
          <el-form-item label="">
            <el-button
              size="small"
              type="primary"
              @click="addition(1)"
              icon="el-icon-plus"
              >新建</el-button
            >
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="24">
        <div>
          <el-table :data="tableData" border style="width: 100%">
            <el-table-column prop="id" label="ID" width="50"> </el-table-column>
            <el-table-column prop="clientName" label="客户名称" width="200">
            </el-table-column>
            <el-table-column prop="level" label="客户级别" width="">
            </el-table-column>
            <el-table-column prop="startingTime" label="开始时间" width="">
            </el-table-column>
            <el-table-column prop="endingTime" label="结束时间">
            </el-table-column>
            <el-table-column prop="type" label="项目类型"> </el-table-column>
            <el-table-column prop="responsible" label="责任人">
            </el-table-column>
            <el-table-column prop="remarks" label="备注"> </el-table-column>
            <el-table-column prop="serialNumber" label="序列号">
            </el-table-column>
            <el-table-column prop="address5" label="项目总结">
            </el-table-column>
            <el-table-column prop="address6" label="结算统计">
            </el-table-column>
            <el-table-column label="操作" width="280" align="center">
              <template #default="scope">
                <el-button
                  size="mini"
                  @click="handleEdit(scope.$index, scope.row)"
                  >复制序列号</el-button
                >
                <el-button
                  size="mini"
                  type="danger"
                  @click="handleDelete(scope.$index, scope.row)"
                  >封存</el-button
                >
                <el-button
                  size="mini"
                  type="success"
                  @click="handleDelete(scope.$index, scope.row)"
                  >作废</el-button
                >
                <el-button
                  size="mini"
                  type="info"
                  style="margin-top: 10px"
                  @click="handleDelete(scope.$index, scope.row)"
                  >下载</el-button
                >
                <el-button
                  size="mini"
                  type="warning"
                  style="margin-top: 10px"
                  @click="handleDelete(scope.$index, scope.row)"
                  >结算统计</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-col>
    </el-row>
    <el-dialog
      :title="single"
      v-model="plassets"
      width="50%"
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="客户名称">
          <el-select
            style="width: 300px"
            v-model="form.customer"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="item in rename"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-button
            @click="newProd()"
            type="success"
            icon="el-icon-plus"
            circle
            size="small"
          ></el-button>
        </el-form-item>
        <el-form-item label="项目类型">
          <el-select
            v-model="form.type"
            clearable
            placeholder="请选择类型"
            style="width: 300px"
          >
            <el-option
              v-for="item in typeData"
              :key="item.value"
              :label="item.label"
              :value="item.code"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="责任人">
          <el-select
            v-model="form.managerId"
            clearable
            placeholder="请选择"
            style="width: 300px"
          >
            <el-option
              v-for="item in managerData"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
          <el-button
            type="success"
            icon="el-icon-plus"
            circle
            size="small"
          ></el-button>
        </el-form-item>
        <el-form-item label="起止时间">
          <el-date-picker
            v-model="newtime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            style="width: 300px"
            v-model="form.addnote"
            type="textarea"
            :rows="2"
          ></el-input>
        </el-form-item>
        <el-form-item label="上传">
          <el-upload
            class="upload-demo"
            action="https://jsonplaceholder.typicode.com/posts/"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            multiple
            :limit="3"
            :on-exceed="handleExceed"
            :file-list="fileList"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <template #tip>
              <div class="el-upload__tip">
                只能上传 jpg/png 文件，且不超过 500kb
              </div>
            </template>
          </el-upload>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer" style="text-align: center">
          <el-button @click="plassets = false">取 消</el-button>
          <el-button type="primary" v-if="under == 1" @click="determine()"
            >确 定</el-button
          >
          <el-button @click="hardware()" v-else type="primary"
            >编辑 确 定</el-button
          >
        </div>
      </template>
    </el-dialog>
    <!-- 新增客户 -->
    <el-dialog
      title="新增客户"
      v-model="newEmp"
      width="35%"
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="news" label-width="80px">
        <el-form-item label="编码" style="width: 300px">
          <el-input v-model="news.encode"></el-input>
        </el-form-item>
        <el-form-item label="姓名" style="width: 300px">
          <el-input v-model="news.username"></el-input>
        </el-form-item>
        <el-form-item label="级别" style="width: 400px">
          <el-radio v-model="news.levels" label="1">VIP</el-radio>
          <el-radio v-model="news.levels" label="2">比较重要</el-radio>
          <el-radio v-model="news.levels" label="3">普通</el-radio>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer" style="text-align: center">
          <el-button @click="plassets = false">取 消</el-button>
          <el-button type="primary" @click="newsdetermine()">确 定</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { type } from "@/api/data";
export default {
  data() {
    return {
      foodName: "",
      form: {
        customer: "",
        type: "",
        managerId: "",
        addnote: "",
      },
      news: {
        encode: "",
        username: "",
        levels: "",
      },
      newtime: "", //起止时间
      plassets: false,
      newEmp: false,
      under: 1,
      single: "",
      rename: [],
      typeData: type,
      managerData: [],
      fileList: [],
      tableData: [],
      m_page: {
        sizes: [10, 20, 40, 50, 100], //每页最大显示数
        size: 10,
        totalElements: 0,
        totalPages: 3,
        number: 1,
      },
      headerObj: "", //请求头
    };
  },
  created() {
    let str = sessionStorage.getItem("token");
    // this.headerObj["Authorization"] = `Bearer ${str}`;
    this.headerObj = `Bearer ${str}`;
  },
  beforeMount() {
    this.author();
    this.getRecord();
  },
  methods: {
    newsdetermine() {},
    newProd() {
      this.newEmp = true;
    },
    addition(index) {
      this.under = index;
      this.single = "新增";
      this.plassets = true;
    },

    getRecord() {
      this.$axios({
        methods: "GET",
        url: "api/serial/ProjectList",
        headers: {
          Authorization: this.headerObj,
        },
        params: {
          pageSize: this.m_page.size,
          pageIndex: this.m_page.number,
          query: {
            categoryName: this.foodName,
          },
        },
      }).then((res) => {
        ({ data: this.tableData, count: this.m_page.totalElements } = res.data);
        // this.loadFlag = false;
      });
    },

    author() {
      this.$axios
        .get(`https://api.jwsci.com/serial/other/staff`, {
          headers: {
            Authorization: this.headerObj,
          },
        })
        .then((res) => {
          // console.log(res);
          let initData = res.data.data;
          console.log(initData);
          initData.forEach((item, index) => {
            this.managerData[index] = {
              value: item.id,
              label: item.name,
            };
          });
        });
    },
    //上传
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
          files.length + fileList.length
        } 个文件`
      );
    },
    beforeRemove(file) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
  },
};
</script>

<style scoped>
.addccc {
  margin-bottom: 20px;
}
</style>